﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LPT_5
{
    public class FormManager
    {
        public delegate void LoginCallback(String sUsername, String sPassword);
        public delegate void ExitCallback();

        private Form mfCurrentForm = null;

        public FormManager()
        { }

        public void Initialise()
        {
            mfCurrentForm = new LoginForm(new LoginCallback(this.MakeCanvas),new ExitCallback(this.AppExit));
            mfCurrentForm.Show();
        }

        public void MakeCanvas(String sUsername, String sPassword)
        {
            Display dfDisplay = new Display(sUsername, sPassword,new ExitCallback(this.AppExit));
            mfCurrentForm.Tag = "FMan";
            mfCurrentForm.Close();
            mfCurrentForm = dfDisplay;
            mfCurrentForm.Show();
        }

        public void AppExit()
        {
            if((String)mfCurrentForm.Tag != "FMan")
                Application.Exit();
        }
    }
}
